﻿@page "/fetchdata"

@using BlazorProject.Data
@inject WeatherForecastService ForecastService

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">搜索</label>
                            <div class="layui-input-block">
                                <input type="text" name="search" placeholder="商户号/公司名称" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="userlist-front-search">查询</button>
                        </div>
                    </div>
                </div>

                <div class="layui-card-body">
                    @if (forecasts == null)
                    {
                        <p><em>Loading...</em></p>
                    }
                    else
                    {
                        <table class="layui-table">
                            <thead>
                                <tr>
                                    <th>Date</th>
                                    <th>Temp. (C)</th>
                                    <th>Temp. (F)</th>
                                    <th>Summary</th>
                                </tr>
                            </thead>
                            <tbody>
                                @foreach (var forecast in forecasts)
                                {
                                    <tr>
                                        <td>@forecast.Date.ToShortDateString()</td>
                                        <td>@forecast.TemperatureC</td>
                                        <td>@forecast.TemperatureF</td>
                                        <td>@forecast.Summary</td>
                                    </tr>
                                }
                            </tbody>
                        </table>
                    }
                </div>
            </div>
        </div>
    </div>
</div>

@code {
    private WeatherForecast[] forecasts;

    protected override async Task OnInitializedAsync()
    {
        forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
    }
}
